Javascript-30-days

View the Project on GitHub delta94/Javascript-30-days

This is a JavaScript practice with JavaScript30 by Wes Bos without any frameworks, no compilers, no boilerplate, and no libraries.

01 - Drum Kit

key event listener, audio play and toggle class.

view demo here

Bind an event to our keys when they are pressed.

window.addEventListener('keydown', playSound)

data-key has its own value on <div>s and <audio>s in HTML

const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);

About playing sounds

How do we prevent delay playing sound, if we keep hitting a key?

just add audio.currentTime = 0; before audio.play();

Toggling styles

if(e.propertyName != 'transform') return;
this.classList.remove('playing'); // `event.target.classList.remove('playing');`

forEach and Arrow function

keys.forEach(key => key.addEventListener());